package com.yu;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yu.dao.UserDao;
import com.yu.pojo.User;
import com.yu.service.UserService;
import com.yu.service.impl.UserServiceImpl;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author DongYu Zhou
 * @date 2022/6/9 10:44
 */
@SpringBootTest
public class SpringBootMpServiceImpl {
    @Autowired
    private UserService userService;
    @Resource
    private UserDao userDao;


    /**
     * 测试查询总条目数 count
     */
    @Test
    public void count() {
        long count = userService.count();
        System.out.println("count = " + count);
    }

    /**
     * 批量添加
     */
    @Test
    public void saveAll() {
        ArrayList<User> users = new ArrayList<>();
        for (int i = 1; i <= 5; i++) {
            User user = new User();
            user.setName("雨"+i);
            user.setAge(18);
            users.add(user);
        }
        boolean b = userService.saveBatch(users);
    }

    /**
     * 逻辑删除
     */
    @Test
    public void deleteL() {
        List<Long> asList = Arrays.asList(2L, 3L);
        int i = userDao.deleteBatchIds(asList);
        System.out.println("i = " + i);
    }

    /**
     * 逻辑删除后查询所有
     */
    @Test
    public void selAll() {
        List<User> userList = userDao.selectList(null);
        for (User user : userList) {
            System.out.println("user = " + user);
        }
    }


}
